package com.herui.iot.ui.report;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.herui.sdyu_lib.adapter.recycle_view.base.ViewHolder;
import com.herui.sdyu_lib.base.FragmentDirectionAnim;
import com.herui.sport_care.R;
import com.herui.sport_care.data.report.Report;
import com.herui.sport_care.data.report.ReportUser;
import com.herui.sport_care.ui.BaseListSportFragment;

import java.util.List;

import butterknife.BindView;

/**
 * 用户列表
 */
public class ReportUserFragment extends BaseListSportFragment<ReportUser> {

    ReportPresenter reportPresenter;

    @BindView(R.id.id_recyclerview_user_list)
    RecyclerView recyclerViewUserList;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_agreement)
    TextView tvAgreement;
    @BindView(R.id.tv_time)
    TextView tvTime;
    private int type;
    private int id;
    private String name;
    private String agreementName;
    private String time;

    public ReportUserFragment() {
        reportPresenter = new ReportPresenter(reportView);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        setTitle(name);
        return view;
    }

    @Override
    public int getLayout() {
        return R.layout.fragment_report_user;
    }

    @Override
    public void initParam() {
        initList(recyclerViewUserList, R.layout.item_single_people_list, false, null);
        reportPresenter.getReportUserList(Long.valueOf(id));
    }

    public static ReportUserFragment newInstance(int type,int id,String name,String agreementName,String time) {
        ReportUserFragment fragment = new ReportUserFragment();
        fragment.type = type;
        fragment.id = id;
        fragment.name = name;
        fragment.agreementName = agreementName;
        fragment.time = time;
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void convert(ViewHolder holder, ReportUser reportUser, int position) {
        holder.setText(R.id.tv_eval_name,reportUser.getBeEvaluatedName());
        holder.setOnClickListener(R.id.view_user, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                    if (type == 1){
                        baseActivity.add(SingleReportDetailFragment.newInstance(
                                reportUser.getId().intValue(),
                                reportUser.getBeEvaluatedName()),
                                new FragmentDirectionAnim()
                        );
                    }else{
                        baseActivity.add(AllReportDetailFragment.newInstance(
                                reportUser
                        ),new FragmentDirectionAnim());
                    }
            }
        });
    }

    @Override
    protected void doRefresh() {

    }

    ReportPresenter.View reportView = new ReportPresenter.View() {
        @Override
        public void onReportUser(List<ReportUser> reportUsers) {
            tvName.setText(name);
            tvAgreement.setText("协议-"+agreementName);
            tvTime.setText(time);

            addData(reportUsers);
        }
    };
}